import requests
import logging
class Test_a3mall():
    token = ""
    def setup_ks(self):
        print("用例开始执行")

    def setup_js(self):
        print("用例执行结束")

    def test_login(self):
        try:
            url = "http://10.59.9.12:7001/api/public/login"
            data = {"username":"13811033962","password":"123456"}
            res =requests.post(url=url,json=data)
            print("登录",res.json())
            Test_a3mall.token = res.json()["data"]["token"]
        except Exception as e:
            logging.info(e)
            assert "13811033962" in res.text

    def test_sousuo1(self):
        try:
            url = "http://10.59.9.12:7001/api/search/list?page=1&keywords=%E5%B0%8F%E7%B1%B3&type=0&sort=1"
            head = {"auth-token":"Bearer " + Test_a3mall.token}
            res = requests.get(url=url,headers=head)
            print("正常搜索成功",res.json())
        except Exception as e:
            logging.info(e)
            #结果断言
            assert "小米有品负离子空气净化器家用除甲醛房间卧室内去烟味小型清新机" in res.text

    def test_sousuo2(self):
        try:
            url = "http://10.59.9.12:7001/api/search/list?"
            head = {"auth-token":"Bearer " + Test_a3mall.token}
            res = requests.get(url=url,headers=head)
            print("搜索为空跳转到商品列表",res.json())
        except Exception as e:
            logging.info(e)
            # 结果断言
            assert "魔怔旗" in res.text

    def test_sousuo3(self):
        try:
            url = "http://10.59.9.12:7001/api/search/list?page=1&keywords=1&type=0&sort=1"
            head = {"auth-token":"Bearer " + Test_a3mall.token}
            res = requests.get(url=url,headers=head)
            print("搜索为单个数字执行成功",res.json())
        except Exception as e:
            logging.info(e)
            # 结果断言
            assert "苹果 17" in res.text

    def test_sousuo4(self):
        try:
            url = "http://10.59.9.12:7001/api/search/list?page=1&keywords=pro&type=0&sort=1"
            head = {"auth-token":"Bearer " + Test_a3mall.token}
            res = requests.get(url=url,headers=head)
            print("搜索多个英文字母商品执行成功",res.json())
        except Exception as e:
            logging.info(e)
            # 结果断言
            assert "苹果 17 pro Max" in res.text

    def test_sousuo5(self):
        try:
            url = "http://10.59.9.12:7001/api/search/list?page=1&keywords=p&type=0&sort=1"
            head = {"auth-token":"Bearer " + Test_a3mall.token}
            res = requests.get(url=url,headers=head)
            print("搜索单个英文字母商品执行成功",res.json())
        except Exception as e:
            logging.info(e)
            # 结果断言
            assert "空气净化器滤网除甲醛雾霾PM2.5办公室氧吧" in res.text

    def test_sousuo6(self):
        try:
            url = "http://10.59.9.12:7001/api/search/list?page=1&keywords=%E5%B0%8F&type=0&sort=1"
            head = {"auth-token":"Bearer " + Test_a3mall.token}
            res = requests.get(url=url,headers=head)
            print("搜索单个中文字符商品执行成功",res.json())
        except Exception as e:
            logging.info(e)
            # 结果断言
            assert ["sale"] ["517"]

    def test_sousuo7(self):
        try:
            url = "http://10.59.9.12:7001/api/search/list?page=1&keywords=%E6%A1%8C%E9%9D%A2%E5%8F%96%E6%9A%96%E5%99%A8%E6%9A%96%E9%A3%8E%E6%9C%BA%E8%BF%B7%E4%BD%A0%E5%B0%8F%E5%9E%8B%E5%8F%96%E6%9A%96%E5%99%A8%E5%AE%B6%E7%94%A8%E9%A3%8E%E6%89%87%E7%94%B5%E6%9A%96%E6%B0%94%E8%8A%82%E8%83%BD&type=0&sort=1"
            head = {"auth-token": "Bearer " + Test_a3mall.token}
            res = requests.get(url=url, headers=head)
            print("搜索10个字符商品执行成功", res.json())
        except Exception as e:
            logging.info(e)
            # 结果断言
            assert  "桌面取暖器暖风机迷你小型取暖器家用风扇电暖气节能" in res.text

    def test_souuso8(self):
        try:
            url = "http://10.59.9.12:7001/api/search/list?page=1&keywords=%40%23%EF%BF%A5%25%E2%80%A6%E2%80%A6%E2%80%A6%E2%80%A6&type=0&sort=1"
            head = {"auth-token":"Bearer " + Test_a3mall.token}
            res = requests.get(url=url,headers=head)
            print("搜索时输入特殊符号执行成功",res.json())
        except Exception as e:
            logging.info(e)
            # 结果断言
            assert ["sale"]["10"]

    def test_sousuo9(self):
        try:
            url = "http://10.59.9.12:7001/api/search/list?page=1&keywords=%20%20%20%20%20%E5%B0%8F%E7%B1%B3&type=0&sort=1"
            head = {"auth-token":"Bearer " + Test_a3mall.token}
            res = requests.get(url=url,headers=head)
            print("搜索时打入空格执行成功",res.json())
        except Exception as e:
            logging.info(e)
            # 结果断言
            assert ["status"]["1"]

    def test_sousuo10(self):
        try:
            url = "http://10.59.9.12:7001/api/search/list?page=1&keywords=2be446577762bb6cec8681f5e2d67d18&type=2&sort=2"
            head = {"auth-token":"Bearer " + Test_a3mall.token}
            res = requests.get(url=url,headers=head)
            print("搜索时输入乱码执行成功",res.json())
        except Exception as e:
            logging.info(e)
            # 结果断言
            assert ["status"]["-1"]





